package com.shop.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.shop.entity.User;
import com.shop.service.UserService;

/**
 * 实现最终修改功能的Servlet
 */
@WebServlet("/Userupdate2")
public class UserupdateServlet2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserupdateServlet2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取修改页面的请求参数，然后调用业务逻辑层对象，实现最终修改
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String msg = "";
		int id=Integer.parseInt(request.getParameter("ids"));
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		User u=new User();
		u.setId(id);
		u.setUsername(username);
		u.setPassword(password);
		System.out.println(u);
		UserService us=new UserService();
		us.updateUser(u);
		msg = "修改成功,请重新登陆";
		request.setAttribute("msg", msg);
		request.getRequestDispatcher("login.jsp").forward(request, response);
		
		
	}

}
